<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="/WEB-INF/tld/c.tld"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>

<head>
<base href="<%=basePath%>">
<title>权限信息编辑1</title>
<meta charset="UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<%@include file="../common/common_ui.jsp" %>
<link href="<%=path%>/js/switch/css/b3/bootstrap-switch.min.css" rel="stylesheet">
<script type="text/javascript" src="<%=path%>/js/switch/js/bootstrap-switch.min.js"></script>
<script type="text/javascript">
function check() {
	if ($('#name').val() == null || $('#name').val().trim() == "") {
		$("#check_alert").show();
		$("#check_content").text("名称不为空！");
		$("#name").focus();
		return false;
	}
	if ($('#parentId').val() == null || $('#parentId').val().trim() == "") {
		$("#check_alert").show();
		$("#check_content").text("所属资源不为空！");
		$("#parentId").focus();
		return false;
	}
	if ($('#url').val().length > 50) {
		$("#check_alert").show();
		$("#check_content").text("url最长50字！");
		$("#url").focus();
		return false;
	}
	if ($('#name').val().length > 50) {
		$("#check_alert").show();
		$("#check_content").text("名称最长50字！");
		$("#name").focus();
		return false;
	}
	if ($('#memo').val().length > 200) {
		$("#check_alert").show();
		$("#check_content").text("备注最长200字！");
		$("#memo").focus();
		return false;
	}
	if ($('#type').val() == null || $('#type').val() == "") {
		$("#check_alert").show();
		$("#check_content").text("权限类型不为空！");
		$("#type").focus();
		return false;
	}
	var orderNumber=new RegExp("^[0-9]{1,5}$");
		if(!orderNumber.test($('#orderNumber').val().trim())){
			$("#check_alert").show();
			$("#check_content").text("序号必须5位及以内数字");
			$("#orderNumber").focus();
			return false; 
		}
	$('#f2').submit();
}

	$(function() {
		$("#type").bootstrapSwitch();
	});
	
	function showMsg(res) {
		if (res != "") {
			$("#check_alert").hide();
			$("#msg_alert").hide();
			if (res == "success") {
				$("#msg_alert").show();
				$("#msg_content").text("新增成功！");
			} else {
				$("#check_alert").show();
				$("#check_content").text(res);
			}
		}
	}
	$(function(){
	/*
	* 关闭提示
	*/
	$(".glyphicon-remove").click(function(){
		$("#check_alert").hide();
		$("#msg_alert").hide();
	});
	});
	
</script>

</head>
<body onload="showMsg('${message}')">
	<form id="f2" class="definewidth m20" action="<%=path%>/resourceInfo/addResource.do" method="post">
	
		<div id="check_alert" class="alert alert-danger mb_0 ng-binding"
			style="display: none;text-align:left">
			<span id="check_content"></span>
			<span class="glyphicon glyphicon-remove"></span>
		</div>
		<div id="msg_alert" class="alert alert-success alert-dismissible"
			role="alert" style="display: none;text-align:left">
			<span id="msg_content"></span>
			<span class="glyphicon glyphicon-remove"></span>
		</div>
	
		<table class="table table-bordered table-hover definewidth m10">
			<tr>
				<td>所属资源：</td>
				<td>
				<select class="form-control" name="parentId" id="parentId" style="width: 250px">
				<option value="">--</option>
				<c:forEach var="info" items="${parentInfo}">
				     <option value="${info.parentId}">${info.parentName}</option>
				</c:forEach>
				</select>
				</td>
			</tr>
			
			<tr>
				<td>名称：</td>
				<td><input name="name" id="name" class="form-control"
						value="${name}" style="width: 250px; height: 50px"></input></td>
			</tr>
			<tr>
				<td>序号：</td>
				<td><input name="orderNumber" id="orderNumber" class="form-control" 
						value="${orderNumber}" style="width: 250px; height: 50px"></input></td>
			</tr>
			<tr>
				<td>URL：</td>
				<td><input name="url" id="url"
						class="form-control" value="${url}"
						style="width: 250px; height: 50px"></input></td>
			</tr>
			
			<tr>
				<td>类型：</td>
				<td>
					<div class="swich swich-small">
						<input name="type" id="type" type="checkbox"
							data-on-text="按钮" data-off-text="菜单" data-on="warning" data-off="danger" />
					</div>
				</td>
			</tr>
			<tr>
				<td>备注：</td>
				<td><textarea name="memo" id="memo"
						class="form-control" value="${memo}"
						style="width: 250px; height: 70px"></textarea></td>
			</tr>
		</table>
		<center>
			<input type="submit" class="btn btn-primary" name="btnSave"
				id="btnSave" onclick="return check();" value="保存" />&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="button" class="btn btn-default" onclick="window.close();" value="关闭" />
		</center>
	</form>
</body>
</html>